<template>
    <view>
<view> 点击领取券</view>
<view v-for="coupon in couponConfigList" class="coupon-config">
    <view class="coupon-name">{{ coupon.name||'未定义' }}</view>
    <button class="coupon-apply" @click="applyCoupon(coupon.id)">领取</button>
</view>
</view>
</template>
<script>
const http = require('../../utils/http.js')
export default {
    data() {
        return {
            couponConfigList:[]
        }

    },
    onLoad() {
        this.getCouponConfigList()
    },
    methods: {
        applyCoupon(id) {
            uni.showLoading()
            const params = {
                url: '/mall4cloud_coupon/a/coupon/applyCoupon',
                method: 'POST',
                data: {
                    couponConfigId: id,
                    pageSize: 10
                },
                callBack: res => {
                    if (!res) {
                                     uni.showToast({
            title: '领取成功'
          })
                        return uni.hideLoading()
                    }
                    console.log("res:", res)
       
                  
                    uni.hideLoading()
                    
                }
            }
            http.request(params)

        },
        getCouponConfigList() {
            uni.showLoading()
            const params = {
                url: '/mall4cloud_coupon/platform/coupon_config/page',
                method: 'GET',
                data: {
                    pageNum: 0,
                    pageSize: 10
                },
                callBack: res => {
                    if (!res) {
                        return uni.hideLoading()
                    }
                    console.log("res:", res)
                    this.couponConfigList = res.list;
                    uni.hideLoading()
                }
            }
            http.request(params)
        }
    }
}
</script>
<style>
@import "./coupon-center.css";
</style>